package com.ck.transaction.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("transaction")
@Slf4j
public class SpringTransactionDemoController {

    @Autowired
    private SpringTransactionDemoService springTransactionService;

    @GetMapping("transaction/{type}")
    public String addSysUserEntity(@PathVariable("type") Integer type) {
        try {
            if (type == 1) {
                this.springTransactionService.addSysUserEntityToDB1();
            } else if (type == 2) {
                this.springTransactionService.addSysUserEntityToDB2();
            } else if (type == 3) {
                this.springTransactionService.addSysUserEntityToDB3();
            } else if (type == 4) {
                this.springTransactionService.addSysUserEntityToDB4();
            } else if (type == 5) {
                this.springTransactionService.addSysUserEntityToDB5();
            } else if (type == 6) {
                this.springTransactionService.addSysUserEntityToDB6();
            } else if (type == 7) {
                this.springTransactionService.addSysUserEntityToDB7();
            } else if (type == 8) {
                this.springTransactionService.addSysUserEntityToDB8();
            } else if (type == 9) {
                this.springTransactionService.addSysUserEntityToDB9();
            } else if (type == 10) {
                this.springTransactionService.addSysUserEntityToDB10();
            } else if (type == 11) {
                this.springTransactionService.addSysUserEntityToDB11();
            } else if (type == 12) {
                this.springTransactionService.addSysUserEntityToDB12();
            } else if (type == 13) {
                this.springTransactionService.addSysUserEntityToDB13();
            } else if (type == 14) {
                this.springTransactionService.addSysUserEntityToDB14();
            }
        } catch (Exception e) {
            log.error("保存用户信息出错：{}", e);
        }
        return "操作成功！";
    }

    /**
     * 保存用户测试方法
     *
     * @return
     * @throws InterruptedException
     */
    @PostMapping("/addSysUserEntityToDB88")
    public String addSysUserEntityToDB88() {
        String addResult = this.springTransactionService.add88SysUserEntityToDB();
        return addResult;
    }

    /**
     * 保存用户测试方法
     *
     * @return
     * @throws InterruptedException
     */
    @PostMapping("/addSysUserEntityToDB99")
    public String addSysUserEntityToDB99() {
        synchronized (this){
            String addResult = this.springTransactionService.add88SysUserEntityToDB();
            return addResult;
        }
    }

}
